package cn.news.biz;

import cn.news.dao.LoginDao;
import cn.news.entity.Admin;
import cn.news.entity.User;
import cn.news.util.SqlSessionFactoryUtil;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

public class LoginBiz {
	
	
	/**
	 * 用户登录
	 * @param uname
	 * @param upass
	 * @return
	 */
	public User user(String uname,String upass){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		LoginDao lDao=(LoginDao)session.getMapper(LoginDao.class);
		User user=new User();
		user.setUname(uname);
		user.setUpass(upass);
		List<User> list=lDao.user(user);
		User us=null;
		for(int i=0;i<list.size();i++){
			us=list.get(i);
		}
		return us;
	}
	/**
	 * 管理员登陆
	 * @param uname
	 * @param upass
	 * @return
	 */
	public Admin admin(String uname,String upass){
		SqlSession session=SqlSessionFactoryUtil.getSqlsession();
		LoginDao lDao=session.getMapper(LoginDao.class);
		Admin admin=new Admin();
		admin.setA_user(uname);
		admin.setA_pass(upass);
		List <Admin> list=lDao.admin(admin);
		Admin am=null;
		for(int i=0;i<list.size();i++){
			am=list.get(i);
		}
		return am;
	}
	
}
